<template>
	<view>
		<component :types="types" :is="componentId"></component>
		<tabBar :pagePath="'/pages/my/my'"></tabBar>
	</view>
</template>

<script>
	import myls from '@/components/mylist/myls.vue'
	import cdglwd from '@/components/mylist/cdglwd.vue'
	import hzgrzx from '@/components/mylist/hzgrzx.vue'
	import sj from '@/components/mylist/sj.vue'
	import zbzrgrzx from '@/components/mylist/zbzrgrzx.vue'
	import lhygrzx from "@/components/mylist/lhygrzx.vue" 
	export default {
		data() {
			return {
				code: '',
				appid: "wx92f28e9b99acb503",
				uid: '',
				udata: '',
				componentId:'',
				types:false
			}
		},
		onLoad() {
				this.getuserinfo();
		},
		onShow(){
			this.getuserinfo();
		},
		methods: {
			async getonLoad() {
				let uid = uni.getStorageSync('uid')
				if (uid == '') {
					this.wechatLogin();
				} else {
					this.getuserinfo();
				}
			},
			async wechatLogin() {
				this.code = this.GetUrlParam('code');
				if (!this.code) {
					let uri = encodeURIComponent(window.location.href);
					window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
						this.appid + "&redirect_uri=" + uri +
						"&response_type=code&scope=snsapi_userinfo&state=state&wechat_redirect&connect_redirect=1#wechat_redirect";
				} else {
					//设置登录信息
					let res = await this.$api.acctokencode({
						code: this.code
					})
					if (res.data.code == 0) {
						//进行缓存数据	
						uni.setStorageSync('uid', res.data.data.id);
						uni.setStorageSync('cdtype', res.data.data.cdtype);
						console.log(res.data.data)
						this.udata = res.data.data
						this.uid = res.data.data.id
						window.location.href = "https://szhwx.ypeport.com/#/pages/my/my";
						// window.location.href = "http://xstow.hephp.cn/index.html#/pages/my/my";
					} else {
						uni.showToast({
							title: '点击重新登录',
							icon: 'none',
							duration: 2000
						});
					}
				}
			},
			async getuserinfo() {
				let data = {
					id: uni.getStorageSync('uid')
				}
				let res = await this.$api.getuserinfo(data)
				console.log(res.data.code)
				if (res.data.code == 0) {
					uni.setStorageSync('uid', res.data.data.id);
					uni.setStorageSync('cdtype', res.data.data.cdtype);
					this.udata = res.data.data
					this.uid = res.data.data.id
					if(res.data.data.status!=1){
						this.types = false
					}else{
						this.types = true
						if(res.data.data.cdtype==1){
							this.componentId = 'sj'
						}else if(res.data.data.cdtype==2){
							this.componentId = 'cdglwd'
						}else if(res.data.data.cdtype==3){
							this.componentId = 'lhygrzx'
						}else if(res.data.data.cdtype==4){
							this.componentId = 'zbzrgrzx'
						}else if(res.data.data.cdtype==5){
							this.componentId = 'hzgrzx'
						}else if(res.data.data.cdtype==6){
							this.componentId = 'myls'
						}
					}
				}
			},
			async logout() {
				uni.removeStorageSync('uid');
				uni.removeStorageSync('cdtype');
				this.uid = '';
				this.udata = [];
			},

			async delched() {
				let data = {
					uid: uni.getStorageSync('uid'),
					cdid: this.udata.cdid
				}
				let res = await this.$api.outcd(data)
				console.log(res.data.code)
				if (res.data.code == 0) {
					uni.showToast({
						title: '退出成功',
						icon: 'none',
						duration: 2000
					});
					this.getuserinfo();
				} else {
					uni.showToast({
						title: '操作异常',
						icon: 'none',
						duration: 2000
					});
				}
			},
		
			

			GetUrlParam(paraName) {
				//微信回调 回回调当前请求的域名 所以需要从链接后获取参数
				var url = document.location.toString();
				var arrObj = url.split("?");
				if (arrObj.length > 1) {
					var arrPara = arrObj[1].split("&");
					var arr;
					for (var i = 0; i < arrPara.length; i++) {
						arr = arrPara[i].split("=");
						if (arr != null && arr[0] == paraName) {
							return arr[1];
						}
					}
					return "";
				} else {
					return "";
				}
			},
		},

		components: {
			cdglwd,
			hzgrzx,
			sj,
			zbzrgrzx,
			lhygrzx,
			myls
		}
	}
</script>

<style lang="scss">
	button.coll {
		background: #fff;
		border: none;
		padding: 0;

		&::after {
			width: 0;
			height: 0;
		}
	}

	.my {
		&.page {
			background-color: #fff;
			padding: 0;
		}

		.user {
			padding-top: 64upx;
			padding-bottom: 32upx;
			flex-direction: column;

			image {
				width: 130upx;
				height: 130upx;
				margin-bottom: 20upx;
				border-radius: 10upx;
			}

			input {
				border: 1px solid #ccc;
				height: 40upx;
				line-height: 40upx;
				padding-left: 10upx;
				border-radius: 10upx;

			}

			.u-edit {
				width: 40upx;
				height: 40upx;
				margin-bottom: 0;
				margin-left: 20upx;
			}
		}

		.cell {
			padding: 30upx 34upx 20upx 36upx;
			border-bottom: 1px solid #dedede;

			.arrow-right {
				width: 16upx;
				height: 28upx;
			}

			.cell-left {
				font-size: 20upx;
				display: flex;
				align-items: center;

				image {
					width: 52upx;
					height: 50upx;
					margin-right: 16upx;
				}
			}
		}

	}

	.ck {
		z-index: 999;
		-moz-opacity: 1;
		opacity: 1;
		// border: 1px solid #000000;
		position: fixed;
		background-color: #ffffff;
		width: 90%;
		border-radius: 5px;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		//padding: 10upx;
	}

	.cks {
		z-index: 999;
		-moz-opacity: 1;
		opacity: 1;
		// border: 1px solid #000000;
		position: fixed;
		background-color: #ffffff;
		width: 90%;
		height: 500px;
		border-radius: 5px;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		//padding: 10upx;
	}


	.uni-list-cell-pd {
		padding: 5px 15px;
	}
</style>
